package com.exam.controller;

import com.exam.pojo.ApiResult;
import com.exam.pojo.Score;
import com.exam.service.ScoreService;
import com.exam.util.ApiResultHandler;
import javafx.util.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ScoreController {
    @Autowired
    private ScoreService scoreService;
    //根据studentId查成绩
    @GetMapping("/score/{studentId}")
    public ApiResult selectScoreById(@PathVariable Integer studentId){
        List<Score> list=scoreService.selectScoreById(studentId);
        return ApiResultHandler.buildApiResult(200,"根据Id查成绩",list);
    }
    @GetMapping("/scores/{examCode}")
    public ApiResult selectScoreAll(@PathVariable Integer examCode){
        List<Score>list=scoreService.selectScoreAll(examCode);
        return ApiResultHandler.buildApiResult(200,"查询所有试卷成绩",list);
    }
    //添加分数
    @PostMapping("/score")
    public ApiResult addScores(@RequestBody Score score){
        int res=scoreService.addScores(score);
        if (res==0){
            return ApiResultHandler.buildApiResult(400, "请求失败！", res);
        }else {
            return ApiResultHandler.buildApiResult(200,"添加成功！", res);
        }

    }
}
